package ProjectTeam39.Domains;
import java.util.ArrayList;

import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;


public class LoginVerifier {
	//create buttons/text fields
	int attempts;
	JButton submit;
	UserList ul;
	JLabel error;
	
	public LoginVerifier(UserList ul){
		//this.submit = submit;
		this.ul = ul;
		//this.error = error;
		attempts = 0;
	}
	
	public int loginAttempt(String user, String pw){
		ArrayList<Patient> patients = ul.getClientelle().getUsers();
		for(int i=0;i<patients.size();i++){
			Patient p = (Patient)patients.get(i);
			if(user.equalsIgnoreCase(p.getUsername()) && p.getStatus() == true){
				if(pw.equalsIgnoreCase(p.getPassword())){
					return 1;
				}
			}
		}
		ArrayList<Nurse> nList = ul.getEmployees().getNurses();
		for(int i=0;i<nList.size();i++){
			Nurse n= nList.get(i);
			if(user.equalsIgnoreCase(n.getUsername()) && n.getStatus() == true){
				if(pw.equalsIgnoreCase(n.getPassword())){
					return 2;
				}
			}
		}
		ArrayList<Doctor> dList = ul.getEmployees().getDoctors();
		for(int i=0;i<dList.size();i++){
			Doctor d = (Doctor)dList.get(i);
			if(user.equalsIgnoreCase(d.getUsername()) && d.getStatus() == true){
				if(pw.equalsIgnoreCase(d.getPassword())){
					return 3;
				}
			}
		}
		ArrayList<SystemAdmin> aList = ul.getEmployees().getAdmins();
		for(int i=0;i<dList.size();i++){
			SystemAdmin a = (SystemAdmin)aList.get(i);
			if(user.equalsIgnoreCase(a.getUsername())){
				if(pw.equalsIgnoreCase(a.getPassword())){
					return 4;
				}
			}
		}
		return 0;
		/*if(attempts>2){
			new ErrorScreen("You have failed to log in");
		}*/
	}//end LoginAttempt
}//end class
